<?php
/**
 * sina用户表数据操作层
 * @author yangchao
 */

class db_sina_users extends db_base {
    
	var $table_name = "sina_users";
	
	function db_user_info()
	{
		parent::db_base();
	}
	
	/**
	 * 前台取用户信息
	 * @param $uid
	 */
	function get_sina_user_info_item_by_sina_uid($sina_uid)
	{
		$mc = mem_cache::get_instance();
		$key = CACHE_PREFIX_USER_ITEM;
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$content = $this->get_alllist($this->table_name,1,1,"","sina_uid='{$sina_uid}' and status=1");
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_TIME_USER_ITEM);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content[0];
		
	}
	
	
	/**
	 * 同步sina用户
	 */
	function insert_sina_user($sina_uid,$access_token,$token_secret,$uid="")
	{
		// 插入数据
		$ary = array();

		$ary["sina_uid"] = $sina_uid;
		$ary["access_token"] = $access_token;
		$ary["token_secret"] = $token_secret;
		if($uid)$ary["uid"] = $uid;
		$ary["create_time"] = Date::get_date_time();
		$ary["status"] = 1;
		
		$ret = $this->insert($this->table_name, $ary);
		
		
		if ($ret)
		{
			/*$memcache = mem_cache::get_instance();
			$memcache->delete($key);*/
		}
		else
		{
			return false;
		}


		return $ret;
	}
	
	

}


?>
